<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>主页</el-breadcrumb-item>
      <el-breadcrumb-item style="font-weight: 700; color: black"
        >访问统计</el-breadcrumb-item
      ><br />
      <el-card class="box-card">
        <el-row>
          <el-button type="text" style="color: #515a"
            ><span class="textfirst">合计访问量：10679</span></el-button
          >
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="">
              <el-input v-model="search" placeholder="搜索关键字"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="getListb">搜索</el-button>
            </el-form-item>
          </el-form>
        </el-row>
        <div class="form">
          <el-table
            border
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
              :header-cell-style="getRowClass"
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="ctime" label="日期" width="511">
              <template slot-scope="scope">
                {{ scope.row.ctime.substring(0, 10) }}
                {{ scope.row.ctime.substring(11, 19) }}
              </template>
            </el-table-column>
            <el-table-column prop="visit" label="访问量" width="511">
            </el-table-column>
            <el-table-column prop="" label="操作"> </el-table-column>
          </el-table>
        </div>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="100"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </el-card>
    </el-breadcrumb>
  </div>
</template>


<script>
import { getListb } from "@/api/two.js";
export default {
  name: "TwoView",
  data() {
    return {
      page: 0,
      size: 10,
      tableData: [],
      total: 10,
      search: "",
    };
  },
  created() {
    this.getListb();
  },
  watch: {
    search(search) {
      this.getListb(search);
      if (!search) {
        this.videos;
        return;
      }
    },
  },
  methods: {
    async getListb() {
      const ruleForm = {
        _orderd: "ctime",
        _page: this.page,
        _size: this.size,
      };
      //搜索
      if (this.search) {
        ruleForm._search = this.search;
        const res = await getListb(ruleForm);
        if (res.code === 1) {
          console.log(res);
          this.tableData = res.list;
          this.total = res.pager.total;
        }
      }
      const res = await getListb(ruleForm);
      if (res.code === 1) {
        console.log(res);
        this.tableData = res.list;
        this.total = res.pager.total;
      }
    },
    // 处理时间
    getCtime(cTime) {
      const time = Date.parse(cTime);
      var date = new Date(time);
      var YY = date.getFullYear() + "-";
      var MM =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hh =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var mm =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var ss =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return YY + MM + DD + " " + hh + mm + ss;
    },
      //设置表头背景颜色
    getRowClass() {
      return "background: #F8F8F9;border:#black;color:515A6E;";
    },
    handleSizeChange(page) {
      this.size = page;
      this.getListb();
    },
    handleCurrentChange(size) {
      this.page = size;
      this.getListb();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-breadcrumb .el-card {
  margin-top: 30px;
  // height: 100%;
}

.el-card .el-row .el-button {
  float: left;
}

.el-card .el-row .el-form {
  float: right;
}

.block {
  margin-top: 20px;
}
.textfirst{
  color:#515A6E;
  font-size:14px;
}
</style>